package org.graduation.model.common.RBAC;

public enum Permissions {
    NULL_PERMISSIONS(-1, "空白权限"),
    // project permissions
    VIEW_PROJECT(0, "查看项目"),
    UPDATE_PROJECT_INFO(1, "修改项目信息"),
    DELETE_PROJECT(2, "删除项目"),
    // task permissions
    VIEW_TASK(3, "查看任务"),
    UPDATE_TASK_INFO(4, "修改任务信息"),
    DELETE_TASK(5, "删除任务"),
    CREATE_TASK(6, "新增任务"),
    CHANGE_TASK_STATUS(7, "修改任务状态"),
    // about admin permissions
    DESIGNATE_ADMIN(8, "任命管理员"),
    REVOKE_ADMIN(9, "撤销管理员"),
    // phase permissions
    CREATE_PHASE(10, "新增项目阶段"),
    UPDATE_PHASE_INFO(11, "修改项目阶段信息"),
    DELETE_PHASE(12, "删除项目阶段"),
    VIEW_PHASE(13, "查看项目阶段"),
    VIEW_NOTE(14, "查看笔记");

    private final int permissionId;
    private final String name;

    Permissions(int permissionId, String name) {
        this.permissionId = permissionId;
        this.name = name;
    }

    /**
     * 提供permissionId获取对应的枚举类
     *
     * @param permissionId
     * @return
     */
    public static Permissions valueOf(int permissionId) {
        for (Permissions permissions : values()) {
            if (permissionId == permissions.getPermissionId()) {
                return permissions;
            }
        }
        return NULL_PERMISSIONS;
    }

    public int getPermissionId() {
        return permissionId;
    }

    public String getName() {
        return name;
    }
}
